package com.wxm.remotemeter.web.action;

import org.apache.commons.lang.StringUtils;

import com.talkweb.ncfw.data.IDataMap;
import com.talkweb.ncfw.data.Page;
import com.talkweb.ncfw.data.ProcessResult;
import com.talkweb.ncfw.exceptions.BaseException;
import com.talkweb.ncfw.web.struts2.ExtGridBaseAction;
import com.talkweb.ncfw.web.utils.HttpServletUtils;
import com.wxm.remotemeter.persistence.entity.Concentrator;
import com.wxm.remotemeter.service.IConcentratorService;

/**
 * <p>文件名称: ConcentratorAction.java</p>
 * <p>文件描述: 集中器控制类</p>
 * <p>版权所有: 版权所有(C)2010</p>
 * <p>内容摘要: 简要描述本文件的内容，包括主要模块、函数及能的说明</p>
 * <p>其他说明: 其它内容的说明</p>
 * <p>完成日期: 2012-2-19</p>
 * <p>修改记录1:</p>
 * <pre>
 *    修改日期:
 *    修 改 人:
 *    修改内容:
 * </pre>
 * <p>修改记录2：…</p>
 * @author  Wuqingming
 */
public class ConcentratorAction extends ExtGridBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 9215032482950649806L;
	
	private IConcentratorService concentratorService;
	private Concentrator concentrator;
	
	public IConcentratorService getConcentratorService() {
		return concentratorService;
	}

	public void setConcentratorService(IConcentratorService concentratorService) {
		this.concentratorService = concentratorService;
	}

	public Concentrator getConcentrator() {
		return concentrator;
	}

	public void setConcentrator(Concentrator concentrator) {
		this.concentrator = concentrator;
	}

	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：录入集中器信息
	 * @return
	 * @throws BaseException
	 */
	public String input () throws BaseException {
		ProcessResult result = null;
		if (StringUtils.isEmpty(concentrator.getConcentratorid())) {	//添加
			this.concentratorService.add(concentrator);
			result = new ProcessResult(true, "集中器信息添加成功");
		} else {	//修改
			this.concentratorService.update(concentrator);
			result = new ProcessResult(true, "集中器信息修改成功");
		}
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}

	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：删除集中器信息
	 * @return
	 * @throws BaseException
	 */
	public String delete () throws BaseException {
		String concentratorids = this.getParameter("concentratorids");
		String[] concentratoridArray = null;
		if (!StringUtils.isEmpty(concentratorids)) {
			concentratoridArray = concentratorids.split(",");
		}
		this.concentratorService.deleteBatch(concentratoridArray);
		ProcessResult result = new ProcessResult(true, "集中器信息删除成功");
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}
	
	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：列出集中器信息
	 * @return
	 * @throws BaseException
	 */
	public String list () throws BaseException {
		Page<Concentrator> page = this.getPage();
		IDataMap<String, Object> condition = this.getParameterMap();
		page = this.concentratorService.find(page, condition);
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			this.bindDataGrid(page);
		}
		return null;
	}

}

